<?php
class UsersController extends AppController {

	public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'admin', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'pages', 'action' => 'display')
        )
    );
    
    public function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->allow('logout');
		$this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'display');
	}

	public function login() {
	    if ($this->request->is('post')) {
	        if ($this->Auth->login()) {
	            $this->redirect($this->Auth->redirect());
	        } else {
	            $this->Session->setFlash('Usuario o contrase&ntilde;a invalidos.');
	        }
	    }
	}

	function logout() {
  		$this->redirect($this->Auth->logout());
	}

    public function index() {
        $this->User->recursive = 0;
        $this->set('users', $this->paginate());
    }
}
?>